package com.businessportal.web.common.longtask.tasks;

import com.businessportal.web.common.longtask.LongTasker;
import com.businessportal.web.dataaccess.entities.Event;
import com.businessportal.web.dataaccess.entities.Login;
import com.businessportal.web.dataaccess.services.EventService;
import com.businessportal.web.dataaccess.services.UserService;

import java.util.Set;

/**
 * Created by Vadim on 12/25/2014.
 */
public class NotificationCheckTask implements Runnable {



    public NotificationCheckTask(){

    }

    @Override
    public void run() {

            try{

                Set<Event> list = EventService.INSTANCE.getEventWithNotification();

                for(Event item : list){
                    Login user = UserService.INSTANCE.GetLoginById(item.getOwner_id());

                    String body = "You marked this event for notification: <br/><br/>" + item.getDescription();

                    LongTasker.Execute(new EmailTask(user.getLogin(),
                            "Event notification",
                            body
                    ));

                    item.setNotify_me(false);

                    EventService.INSTANCE.Update(item);
                }

            }catch(Exception e){

            }
    }
}
